package 滑动;

import java.util.Arrays;

public class _1423可获得的最大点数 {
    public static int maxScore(int[] cardPoints, int k) {
        int sum = 0;
        int min = Integer.MAX_VALUE;
        int window = cardPoints.length - k;// 7
        int all = 0;
        if (window == 0) {
            return Arrays.stream(cardPoints).sum();
        }
        for (int i = 0; i < cardPoints.length; i++) {
            all += cardPoints[i];
            sum += cardPoints[i];
            if (i < window - 1) {
                continue;
            }
            min = Math.min(min, sum);
            sum -= cardPoints[i - window + 1];
        }

        return all - min;
    }

    public static void main(String[] args) {
        // System.out.println("==============="+maxScore(new int[]{1,2,3,4,5,6,1}, 3));
        System.out.println("==============="+maxScore(new int[]{9,7,7,9,7,7,9}, 7));
    }
}
